<?php
use yii\helpers\Url;
$this->context->layout = false;
?>
<?php
//使用率
echo $this->render("@app/views/public/useRate.php")
?>
<div id="Personal-Early-Time-List"></div>
<script>
	var Personal_early_time_grid = $("#Personal-Early-Time-List");
	$(document).ready(function() {
		Personal_early_time_grid.kendoGrid({
			dataSource: {
				transport: {
					read:function (e) {
						$.ajax({
							url: "<?=Url::to(['personearlytimelist']); ?>",
							dataType: "json",
							success:function (redata) {
								e.success(redata);
							}
						})
					},
					update:function (e) {
						$.ajax({
							url: "<?=Url::to(['modifyearlytime']); ?>",
							data:e.data,
							dataType: "json",
							success:function (redata) {
								if(redata.status == 1){
									var Personal_kendo = Personal_early_time_grid.data("kendoGrid");
									Personal_kendo.dataSource.read();
									Personal_kendo.refresh();
								}else{
									layer.msg(redata.info, {icon: 5});
								}
							}
						})
					},
					parameterMap: function(options, operation) {
						if (operation !== "read" && options.models) {
							return {models: kendo.stringify(options.models)};
						}
					}
				},
				schema: {
					model: {
						id:"cn_early_time_id",
						fields: {
							cn_early_time_id: { field:"cn_early_time_id"},
							early_time: { field:"early_time",type:"date"},
							progress: { field:"progress",editable:false},
							created: { field:"created",editable:false,type:"date"}
						}
					}
				},
				pageSize: 20
			},
			filterable: {
                extra: false,
                operators: {
                    string: {
                        contains: "包含",
                        doesnotcontain: "不包含",
                        eq: "等于",
                        neq: "不等于"
                    }
                }
            },
			editable: "inline",
			pageable:{
					refresh: true,//刷新按钮
					pageSizes: [20, 40, 60, "all"],//每页数量选择
					buttonCount: 5//页码按钮数量
			},
			columns: [
                {
                    field:"created",
                    title: "发布日期(美国时间)" ,
                    format: "{0:MM/dd/yyyy HH:mm}",
                    headerAttributes: alignCenterAttribute,
                    attributes: alignCenterAttribute
                },
				{
					field:"early_time",
					title: "早班日期(美国时间)" ,
					format: "{0:MM/dd/yyyy}",
					headerAttributes: alignCenterAttribute,
					attributes: alignCenterAttribute
				},
				{
					field:"progress",
					title:"申请进度",
					template:function(e){
                        var dt = new Date(e.early_time);
                        var date = [
                            [dt.getFullYear(), dt.getMonth() + 1, dt.getDate()].join('-'),
                            [dt.getHours(), dt.getMinutes(), dt.getSeconds()].join(':')
                        ].join(' ').replace(/(?=\b\d\b)/g, '0'); // 正则补零
                        // if(get_unix_time(date)< Date.parse(new Date())/1000){
                        // 	return "暂未申请!！";
                        //     //return "早班时间已过期";
                        // }
						if(e.early_time == null){
							return "";
						}else{
							if(e.progress == 1){
								return "等待审核<br/>申请时间:"+e.early_apply_time;
							}else if(e.progress == 2){
								return "通过审核<br/>早班时间已更改";
							}else if(e.progress == 3){
								return "审核不通过<br/>理由："+e.reason;
							}
						}
						return "暂未申请！";
					},
					headerAttributes: alignCenterAttribute,
					attributes: alignCenterAttribute
				},
				{
					title:"申请修改早班時間",
					command: [{name:"edit",text:{edit:"申请修改"}}],
					headerAttributes: alignCenterAttribute,
					attributes: alignCenterAttribute
				}
			]
		});
	});
	function get_unix_time(dateStr)
	{
		var newstr = dateStr.replace(/-/g,'/');
		var date =  new Date(newstr);
		var time_str = date.getTime().toString();
		return time_str.substr(0, 10);
	}
</script>
